#!/usr/bin/env node

const {EventEmitter} = require("events");

class Dog extends EventEmitter {
    constructor(name, energy) {
        super();
        this.#name = name;
        this.#energy = energy;
        this.#start();
    }

    get name() {return this.#name;}
    get energy() {return this.#energy;}
    set energy(e) {
        this.#energy = e;
        this.#start();
    }
    
    #start() {
        let timer = setInterval(() => {
            this.emit('bark');
            this.#energy--;
            if(this.#energy === 0) clearInterval(timer);
        }, 1000);

    }
    #name='';
    #energy=0;
}

module.exports = Dog;